﻿/*
date	 :2010-10-1
author	 :writed by wangchao,cwangchao@gmail.com
*/
Array.prototype.Remove = function(n) {
    if (n < 0)
    return this;
    else
    return this.slice(0, n).concat(this.slice(n + 1, this.length));

}

var clickEvents = new Array();
var xmlDom = null;
var lastClickTarget = null;

function CloseWin() {
    window.opener = null;
    window.open('', '_self');
    window.close();

}
function SelectAll(chkAll) {
    var inputs = document.forms[0].elements;
    for (var i = 0; i < inputs.length; i++) {
        if (inputs[i].type == 'checkbox') {
            inputs[i].checked = chkAll.checked;

        }

    }

}
function BindClick(id, fn, param) {
    var e = new Object();
    e.id = id;
    e.func = fn;
    e.param = param;
    clickEvents.push(e);

}
function UnbindClick(idtobeunbind) {
    for (var i in clickEvents) {
        if (clickEvents[i].id == idtobeunbind) {
            clickEvents.Remove(i);
            break;

        }

    }

}
function GetLastClickTarget() {
    return lastClickTarget;

}
/*get a target from window.event*/
function GetTarget(e) {
    if (e == null || typeof(e) == "undefined")
    e = window.event;
    return ((typeof e.target != "undefined") ? e.target: e.srcElement);

}
/*catch mouse click*/
function OnMouseDown(e) {
    if (e == null || typeof(e) == "undefined")
    e = window.event;
    var temp = GetTarget(e);
    if (temp == null)
    return false;
    lastClickTarget = temp;
    s = temp.id;
    for (var i in clickEvents) {
        if (s == clickEvents[i].id) {
            clickEvents[i].func(clickEvents[i].param);
            break;

        }

    }
	return;
}
function AddMouseDownListener(fn) {
    var oldfn = document.onmousedown;
    if (typeof oldfn != 'function') {
        document.onmousedown = fn;

    }
    else {
        document.onmousedown = function() {
            oldfn();
            fn();
        };

    }

}

function AddLoadListener(fn) {
    if (typeof window.addEventListener != 'undefined') {
        window.addEventListener('load', fn, false);

    }
    else if (typeof document.addEventListener != 'undefined') {
        document.addEventListener('load', fn, false);

    }
    else if (typeof window.attachEvent != 'undefined') {
        window.attachEvent('onload', fn);

    }
    else {
        var oldfn = window.onload;
        if (typeof oldfn != 'function') {
            window.onload = fn;

        }
        else {
            window.onload = function() {
                oldfn();
                fn();
            };

        }

    }

}
//fast get object
function $() {
    var elements = new Array();
    for (var i = 0; i < arguments.length; i++) {
        var element = arguments[i];
        if (typeof element == 'string')
        element = document.getElementById(element);
        if (arguments.length == 1)
        return element;
        elements.push(element);

    }
    return elements;

}
//xmldom
function GetXMLDOM() {
    if (xmlDom)
    return xmlDom;
    if (window.ActiveXObject) {
        //ie
        xmlDom = new ActiveXObject("Microsoft.XMLDOM");

    }
    else if (document.implementation.createDocument) {
        //Mozilla, Firefox, Opera, etc.
        xmlDom = document.implementation.createDocument("", "", null);

    }
    xmlDom.async = false;

    return xmlDom;

}
//load xml
function LoadXML(url) {
    xmlDom = GetXMLDOM();
    xmlDom.load(url);
    return xmlDom;

}

//MakeRequest,default is ansy=true
function MakeRequest(url, method, data, request_fun) {
    try
    {
        CRequestor.Request(url, method, data, request_fun, true);
    } catch (e) {
        alert(e)   
    }
}

/* cookie operations */
function ReadCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);

    }
    return "";

}

function IfExistedJS(src) {
    scriptArry = document.getElementsByTagName('script');
    for (var i=0;i<scriptArry.length;i++)
    {
        if (scriptArry[i].src.toString() == src.toString())
        {
            return true;
        }

    }
    return false;

}

/*
1.if js is function 
    1.if function in this file 
    2.if function not in this file
2.if js is js
*/
function ExcuteObj(obj) {
    if (obj == null || obj.toString() == "")//||typeof obj=="undefined")
    return;
    if (typeof obj == "function") {
        obj();
        return;

    }

    var str = obj;
    try
    {
        var reg = new RegExp(/^[a-zA-Z0-9|_]{1,20}$/);
        if (reg.test(str))
        {
            eval(str + "();")
        }
        else
        {
            eval(str);

        }
        reg = null;
    }
    catch(e)
    {
        alert(e.message);
    }

}
/*
sorry,this function may be named SynLoadScript
*/
function AnsyLoadScript(src, js) 
{
	//if existed
    if (IfExistedJS(src))
    {
        return;
        //warning!if existed js,callback fun won't be called.

    }
    //if not existed
    var script = document.createElement("script");
	script.ansy=true;
    script.type = "text/javascript";
    if (script.readyState) 
    {
        //IE
        script.onreadystatechange = function()
       	{
            if (script.readyState == "loaded" || script.readyState == "complete")
	    	{
                script.onreadystatechange = null;
                ExcuteObj(js);
            }
        }
    }
    else
    {
        //Others
        script.onload = function()
        {
            ExcuteObj(js);
        };

    }
    script.src = src;
    document.getElementsByTagName("head")[0].appendChild(script);
}
/*
src     :js file name,if not existed,than will be loaded.
callback:function will be called;
*/
function CallEx(src, js) {
    //if existed
    if (IfExistedJS(src)) {
        ExcuteObj(js);

    }
    else {
        AnsyLoadScript(src, js);

    }

}
/*
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
*/
(function Firefox_innerText() {
    var index=window.navigator.userAgent.toLowerCase().indexOf("msie");
    if(index==-1)
    { //firefox innerText   
       HTMLElement.prototype.__defineGetter__(     "innerText",  
        function(){  
         var anyString = "";  
         var childS = this.childNodes;  
         for(var i=0; i<childS.length; i++) {  
          if(childS[i].nodeType==1)  
           anyString += childS[i].tagName=="BR" ? '\n' : childS[i].textContent;  
          else if(childS[i].nodeType==3)  
          anyString += childS[i].nodeValue;  
        }  
          return anyString;  
       }  
      );  
      HTMLElement.prototype.__defineSetter__(     "innerText",  
       function(sText){  
        this.textContent=sText;  
       }  
      );  
    }   
})();

var GetXMLNodeValue = function(obj)
{
	var str = "";
	if (window.ActiveXObject)
	//IE
	{
		str = obj.text;
	}
	else
	//Mozilla
	{
		try
		{
			str = obj.childNodes[0].nodeValue;
		}
		catch(ex)
		{
			str = "";
		}
	}
	return str;
};
/*
(function IE_FireFox_XMLDoc(){
	
	if (document.implementation && document.implementation.createDocument)
	 {
		XMLDocument.prototype.loadXML = function(xmlString)
		{
			var childNodes = this.childNodes;
			for (var i = childNodes.length - 1; i >= 0; i--)
			this.removeChild(childNodes[i]);
	
			var dp = new DOMParser();
			var newDOM = dp.parseFromString(xmlString, "text/xml");
			var newElt = this.importNode(newDOM.documentElement, true);
			this.appendChild(newElt);
	
		};
		// check for XPath implementation
		if (document.implementation.hasFeature("XPath", "3.0"))
		{
			// prototying the XMLDocument
			XMLDocument.prototype.selectNodes = function(cXPathString, xNode)
			{
				if (!xNode) {
					xNode = this;
				}
				var oNSResolver = this.createNSResolver(this.documentElement)
				var aItems = this.evaluate(cXPathString, xNode, oNSResolver, 
				XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)
				var aResult = [];
				for (var i = 0; i < aItems.snapshotLength; i++)
				{
					aResult[i] = aItems.snapshotItem(i);
	
				}
				return aResult;
	
			}
			// prototying the Element
			Element.prototype.selectNodes = function(cXPathString)
			{
				if (this.ownerDocument.selectNodes)
				{
					return this.ownerDocument.selectNodes(cXPathString, this);
				}
				else {
					throw "For XML Elements Only";
				}
			}
		}
		// check for XPath implementation
		if (document.implementation.hasFeature("XPath", "3.0"))
		{
			// prototying the XMLDocument
			XMLDocument.prototype.selectSingleNode = function(cXPathString, xNode)
			{
				if (!xNode) {
					xNode = this;
				}
				var xItems = this.selectNodes(cXPathString, xNode);
				if (xItems.length > 0)
				{
					return xItems[0];
	
				}
				else
				{
					return null;
	
				}
			}
			// prototying the Element
			Element.prototype.selectSingleNode = function(cXPathString)
			{
				if (this.ownerDocument.selectSingleNode)
				{
					return this.ownerDocument.selectSingleNode(cXPathString, this);
	
				}
				else {
					throw "For XML Elements Only";
				}
			}
		}
	}
})();*/
/*
scriptLoader.load([
  'http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js',
  'http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js'
  'your-script.js'
]);
*/
var ScriptLoader = 
{
	_loadScript: function (url, callback) 
	{
		var head = document.getElementsByTagName('head')[0];
		var script = document.createElement('script');
		script.type = 'text/javascript';
		script.src = url;
		//script.ansy=false;
		if (callback) 
		{
			script.onreadystatechange = function () 
			{
				if (this.readyState == 'loaded') callback();
			}
			script.onload = callback;
		}
		head.appendChild(script);
	},
	load: function (items, iteration) 
	{
		if (!iteration) iteration = 0;
		if (items[iteration]) 
		{
			ScriptLoader._loadScript(items[iteration],function () {ScriptLoader.load(items, iteration+1);});
		}
	}
}
var AnsyLoadScriptList=
{
	 items:0,
	 allcallback:0,
	 percallback:0,
	 current:0,
	 loadedone:function()
	 {
		 try
		 {
		 	ExcuteObj(percallback);
		 }
		 catch(e)
		 {}
	 },
	 loadedall:function()
	 {
		  try
		 {
			 ExcuteObj(this.percallback);
			 ExcuteObj(this.allcallback);
		 }
		 catch(e)
		 {}
	 },
	 loadone:function()
	 {
		this.AnsyLoadScript(this.items[this.current]); 
     },
	 loadall:function()
	 {
		 this.loadone(0);
	 },
	 IfExistedJS:function(src) 
	 {
		var scriptArry = document.getElementsByTagName('script');
		for (var i=0;i<scriptArry.length;i++)
		{
			if (scriptArry[i].src.toString() == src.toString())
			{
				return true;
			}
		}
		return false;

	},
	scriploaded:function()
	{
		if (this.script.readyState) 
		{
			if (this.script.readyState == "loaded" || this.script.readyState == "complete")
			{
					this.script.onload=null;
					this.script.onreadystatechange = null;
					this.current++;
					if(this.current!=this.items.length)
					{
						this.loadedone();
						this.AnsyLoadScript(this.items[this.current]);
					}
					else
					{
						this.loadedone();
						this.loadedall();
					}
			}
		}
		else
		{
					this.script.onload=null;
					this.script.onreadystatechange = null;
					this.current++;
					if(this.current!=this.items.length)
					{
						this.loadedone();
						this.AnsyLoadScript(this.items[this.current]);
					}
					else
					{
						this.loadedone();
						this.loadedall();
					}
		}
	}
	,
	script:0
	,
	AnsyLoadScript:function (src) 
	{
		//if existed
		if (this.IfExistedJS(src))
		{
			return;
			//warning!if existed js,callback fun won't be called.
	
		}
		//if not existed
		this.script = document.createElement("script");
		//this.script.ansy=true;
		this.script.type = "text/javascript";
		
		var oThis = this;
		if (this.script.readyState) 
		{
			//IE
			this.script.onreadystatechange = function()
			{
				oThis.scriploaded();
			}
		}
		else
		{
			//Others
			this.script.onload  = function()
			{
				oThis.scriploaded();
			}
	
		}
		this.script.src = src;
		document.getElementsByTagName("head")[0].appendChild(this.script);
	}
	
}
function $Import(Items,percallback,allcallback)
{
    var a = AnsyLoadScriptList; //clone(false)
	a.items=Items;
	a.percallback = percallback;
	a.allcallback = allcallback;
	a.loadall();
}
var ExecQueue = function() 
{
	this.queue = [];
};
ExecQueue.prototype = 
{
	add : function(fn, args, time) 
	{
		this.queue.push( 
		{
			fn : fn,
			args : args,
			time : time
		});
	},
	exec : function() 
	{
		var delay = 0;
		for ( var i = 0; i < this.queue.length; i++)
		{
			var _this=this;
			var f=function(idx)
			{
				return function()
				{
					_this.queue[idx].fn.apply(_this,_this.queue[idx].args);
				}
			}(i);
			setTimeout(f, delay);
			delay += this.queue[i].time;
		}
	}
}
function  Sleep() 
{ 
	var   start=new   Date().getTime(); 
	while(true)   if(new   Date().getTime()-start> n)   break;
}
function Delay()
{

}
/*
function a(){
	alert('a');
}
function b(i){
	alert('b'+i);
}
function c(i,j){
	alert('c'+i+j);
}
var execqueue=new ExecQueue();
execqueue.add(a,[],5000);
execqueue.add(b,['i'],5000);
execqueue.add(c,['c1','c2'],5000);
execqueue.add(c,['c3','c4'],2000);
execqueue.exec();
*/
